package com.yanqu.road.server.cmd.activity.autoreward.rank;

import com.yanqu.road.entity.enums.eCrossUnionRankActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.rank.cross.CrossUnionActivityRank;
import com.yanqu.road.logic.cross.CrossUnionActivityRankListModel;
import com.yanqu.road.pb.activity.AutoSendRewardProto;
import com.yanqu.road.server.manager.activity.ActivityRankMgr;

/**
 * @author ：zfr
 * @date ：2021/8/10 14:21
 */
public class CrossUnionActivityChildRank extends BaseCrossRank {
    private int childType;

    public CrossUnionActivityChildRank(int activityId, int childType) {
        super(activityId);
        this.childType = childType;
    }

    @Override
    public AutoSendRewardProto.CrossUserRankMsg.Builder getCrossUserRankMsg() {
        return null;
    }

    @Override
    public AutoSendRewardProto.CrossUnionRankMsg.Builder getCrossUnionRankMsg() {
        AutoSendRewardProto.CrossUnionRankMsg.Builder msg = AutoSendRewardProto.CrossUnionRankMsg.newBuilder();
        msg.setActivityId(activityId);
        CrossUnionActivityRankListModel rankListModel = ActivityRankMgr.getCrossActivityUnionRankListModel(activityId);
        if (rankListModel != null) {
            int conditionType;
            if(eCrossUnionRankActivityType.unionEarnSpeedRiseRank.getIntValue() == childType){
                conditionType = eGamePlayerEventType.UnionEarnSpeedRiseRank.getValue();
            }else if(eCrossUnionRankActivityType.unionIntimacyRiseRank.getIntValue() == childType){
                conditionType = eGamePlayerEventType.UnionIntimacyRiseRank.getValue();
            }else if(eCrossUnionRankActivityType.unionExpRiseRank.getIntValue() == childType){
                conditionType = eGamePlayerEventType.UnionExpRiseRank.getValue();
            }else {
                throw new RuntimeException("unionActivity childType no set conditionType, childType:" + childType);
            }
            int rank = 0;
            if (rankListModel != null) {
                for (CrossUnionActivityRank rankData : rankListModel.getRankList()) {
                    String unionUid = rankData.getUnionUid();
                    rank++;
                    addUnionRankData(msg, conditionType, unionUid, rank);
                }
            }
        }
        return msg;
    }
}
